package com.lonwin.inspectionmanagement.mvp.model;

import android.app.Application;

import com.google.gson.Gson;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;

import com.jess.arms.di.scope.ActivityScope;

import javax.inject.Inject;

import com.lonwin.inspectionmanagement.mvp.contract.HomeCruiseContract;
import com.lonwin.inspectionmanagement.mvp.model.api.service.BusinessService;
import com.lonwin.inspectionmanagement.mvp.model.entity.bean.NLocusSResult;
import com.lonwin.inspectionmanagement.mvp.model.entity.bean.PatrolBean;
import com.lonwin.inspectionmanagement.mvp.model.entity.bean.QueryNumBean;
import com.lonwin.inspectionmanagement.mvp.model.entity.bean.SearLocusBean;

import java.util.Map;

import io.reactivex.Observable;
import io.reactivex.functions.Function;


@ActivityScope
public class HomeCruiseModel extends BaseModel implements HomeCruiseContract.Model {
    @Inject
    Gson mGson;
    @Inject
    Application mApplication;

    @Inject
    public HomeCruiseModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }

    @Override
    public Observable<String> updateData(String url,Map<String,String> data) {

        return mRepositoryManager.obtainRetrofitService(BusinessService.class).updateData(url,data)
                .map(new Function<String, String>() {
                    @Override
                    public String apply(String s) throws Exception {
                        return s;
                    }
                });
    }

    @Override
    public Observable<PatrolBean> startPatrol(String url, Map<String, String> params) {
        return mRepositoryManager.obtainRetrofitService(BusinessService.class).startPatrol(url,params)
                .map(new Function<PatrolBean, PatrolBean>() {
                    @Override
                    public PatrolBean apply(PatrolBean patrolBean) throws Exception {
                        return patrolBean;
                    }
                });
    }

    @Override
    public Observable<PatrolBean> endPatrol(String url, Map<String, String> params) {
        return mRepositoryManager.obtainRetrofitService(BusinessService.class).endPatrol(url,params)
                .map(new Function<PatrolBean, PatrolBean>() {
                    @Override
                    public PatrolBean apply(PatrolBean patrolBean) throws Exception {
                        return patrolBean;
                    }
                });
    }

    @Override
    public Observable<NLocusSResult> cpathTemp(String url, Map<String, Object> maps) {
        return mRepositoryManager.obtainRetrofitService(BusinessService.class).cpathTemp(url,maps).map(new Function<NLocusSResult, NLocusSResult>() {
            @Override
            public NLocusSResult apply(NLocusSResult nLocusSResult) throws Exception {
                return nLocusSResult;
            }
        });
    }

    @Override
    public Observable<NLocusSResult> getMyLastXcpath(String url, Map<String, Object> params) {
        return mRepositoryManager.obtainRetrofitService(BusinessService.class).getMyLastXcpath(url,params);
    }

    @Override
    public Observable<NLocusSResult> continueXcpathTemp(String url, Map<String, Object> params) {
        return mRepositoryManager.obtainRetrofitService(BusinessService.class).continueXcpathTemp(url, params);
    }
    @Override
    public Observable<QueryNumBean> getHzUnCheckXcjlbCount(String url, Map<String, Object> params) {
        return mRepositoryManager.obtainRetrofitService(BusinessService.class).getHzUnCheckXcjlbCount(url,params);
    }
}